# -*- coding: utf-8 -*-
from PyQt4.QtGui import *
from PyQt4.QtCore import *

dialog = None

def myerrorhandler(cursor, errorclass, errorvalue):
	"""

	If cursor is not None, (errorclass, errorvalue) is appended to
	cursor.messages; otherwise it is appended to
	connection.messages. Then errorclass is raised with errorvalue as
	the value.

	You can override this with your own error handler by assigning it
	to the instance.

	"""
	global dialog

	error = errorclass, errorvalue
	if cursor:
		cursor.messages.append(error)
	del cursor

	string = str(errorclass) + ": " + str(errorvalue)
	dialog = QMessageBox(QMessageBox.Critical, "Database Error", string, QMessageBox.Ok)
	dialog.show()

	raise errorclass, errorvalue
